""" Newforms Admin configuration for Photologue

"""
from django.contrib import admin
from models import *
from widgets import ThumbnailInput, LinkInput

class GalleryAdmin(admin.ModelAdmin):
    list_display = ('title', 'date_added', 'photo_count', 'is_public')
    list_filter = ['date_added', 'is_public']
    date_hierarchy = 'date_added'
    prepopulated_fields = {'title_slug': ('title',)}
    filter_horizontal = ('photos',)

class FilePhotoAdmin(admin.ModelAdmin):
    list_display = ('title', 'date_taken', 'date_added', 'is_public', 'tags', 'view_count', 'admin_thumbnail')
    list_filter = ['date_added', 'is_public']
    search_fields = ['title', 'caption']
    list_per_page = 10
    prepopulated_fields = {'title_slug': ('title',)}
    exclude = ('photo_type')
    
class FlickrPhotoAdmin(admin.ModelAdmin):
    list_display = ('title',  'date_added', 'is_public', 'tags',  'admin_thumbnail')
    list_filter = ['date_added', 'is_public']
    search_fields = ['title', 'caption']
    list_per_page = 10
    prepopulated_fields = {'title_slug': ('title',)}
    class Media:
        css = {
            "all": ("/static/djangollery/css/thickbox.css",)
        }
        js = ("/static/djangollery/js/jquery-1.1.3.1.js",
              "/static/djangollery/js/thickbox.js")
    
    def formfield_for_dbfield(self, db_field, **kwargs):
        field = super(FlickrPhotoAdmin, self).formfield_for_dbfield(db_field, **kwargs) 
        if db_field.name == "thumbnail":
            field.widget=ThumbnailInput()
        elif db_field.name == "display" or db_field.name == "original": 
            field.widget=LinkInput()
        return field






admin.site.register(Gallery, GalleryAdmin)
admin.site.register(FilePhoto, FilePhotoAdmin)
admin.site.register(FlickrPhoto,FlickrPhotoAdmin)
